package com.wanxi.controller.message;

import com.wanxi.domain.ResultModel;
import com.wanxi.domain.message.MessageModel;
import com.wanxi.service.message.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("message")
@RestController
@CrossOrigin(allowCredentials = "true", origins = "http://localhost:63342", allowedHeaders = "*")//允许跨域请求
public class MessageController {

    @Autowired
    private MessageService messageService;

    /*发送邮件到反馈用户*/
    @PostMapping("sendMail")
    public String sendMail(@RequestBody MessageModel messageModel){

        String resultModel = messageService.sendQQ(messageModel);

        return resultModel;
    }

    /*查询所有的用户反馈*/
    @GetMapping("allMessage")
    public List<MessageModel> getAllMessage(int page, int limit) {

        page = (page - 1) * limit;

        List<MessageModel> resultModel = messageService.selectAll(page, limit);

        return resultModel;
    }

    /*根据id查询用户反馈*/
    @GetMapping("findById")
    public MessageModel getMessageById(int id) {
        MessageModel resultModel = messageService.findById(id);
        return resultModel;
    }

    /*添加用户反馈*/
    @PostMapping("feedback")
    public int insertMessage(@RequestBody MessageModel messageModel) {

        int resultModel = messageService.insert(messageModel);

        return resultModel;

    }

    /*获取用户反馈数量*/
    @GetMapping("count")
    public int getCount(){

        int resultModel  =  messageService.getCount();

        return resultModel;
    }

    /*更改用户反馈回复状态*/
    @PostMapping("updateById")
    public int updateMessage(@RequestBody MessageModel messageModel){

        int resultModel = messageService.updateById(messageModel.getId());

        return resultModel;
    }

    /*删除回复*/
    @PostMapping("delete")
    public int deleteMessage(@RequestBody MessageModel messageModel){
        int num =  messageService.delete(messageModel.getId());
        return num;
    }
}
